//
//  HostViewController.m
//  SuperRadio
//
//  Created by Damon on 14/12/17.
//  Copyright (c) 2014年 三个臭皮匠. All rights reserved.
//

#import "HostViewController.h"
#import "NetHandler.h"
#import "Host.h"
#import "UIImageView+WebCache.h"
#import "AlbumOfListCell.h"
#import "AlbumOfList.h"
#import "AlbumDatailsOfList.h"
#import "AlbumDetailsCell.h"
#import "Introduction.h"
#import "HostLikeViewController.h"
#import "HostAttentionViewController.h"
#import "AllAlbumOfHostViewController.h"
#import "AlbumDetailsViewController.h"
#import "MainPlayerViewController.h"
#import "DeatilsViewController.h"


#import "UIScrollView+MJRefresh.h"
#import "UIScrollView+Extension.h"

#import "AudioPlayer.h"
#import "AudioButton.h"

#define DETAIL_HIGHT 220   //显示图片的高度
#define FINAL_HIGHT 60   //上拉滑动最终留下的显示图片高度
#define IMAGEVIEW_ORIGIN_Y - 60 //图片的实际七点纵坐标
#define IMAGEVIEW_ORIGIN_HEITH 300  //图片的实际高度


@interface HostViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic, retain)UIView *titleView;
@property(nonatomic, retain)UIButton *button;
@property(nonatomic, retain)UIButton *buttonZan;
@property(nonatomic, retain)UILabel *titleLightView;
@property(nonatomic, retain)UILabel *titleLable;
@property(nonatomic,retain)UITableView *tableV;
@property(nonatomic, retain)NSMutableArray *arr;
@property(nonatomic, retain)Host *host;
@property(nonatomic, retain)NSMutableArray *albumArr;
@property(nonatomic, retain)NSMutableArray *soundArr;


//背景图片
@property(nonatomic, retain)UIImageView *imageView;
//博主头像
@property(nonatomic, retain)UIImageView *hostImageView;
//博主名字
@property(nonatomic, retain)UILabel *HostNameLable;
//博主备注
@property(nonatomic, retain)UILabel *HostRemarkLable;

@property(nonatomic, retain) NSNumber *albumTotalCount;

@property(nonatomic, retain) NSNumber *soundTotalCount;


// 当前的请求页数
@property (nonatomic, assign) NSInteger pageId;
// 最大得页数
@property (nonatomic, assign) NSInteger maxPageId;



@property (nonatomic, assign) NSInteger cellTag;

@property (nonatomic, retain)AudioButton *audioBtn;

@property(nonatomic, retain) MainPlayerViewController *mainPlayVC;

@property (nonatomic, retain)AlbumDetailsCell *cell;

@end

@implementation HostViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
        self.pageId = 1;
        
        
        self.introduction = [[Introduction alloc] init];
        self.albumArr = [NSMutableArray array];
        self.soundArr = [NSMutableArray array];
    }
    return self;
}

//解析最上面博主信息的数据
- (void)handleData
{
    
      NSString *str = [NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/others/ca/homePage?device=iPhone&toUid=%@", self.introduction.uid];

    [NetHandler getDataWithURL:str completion:^(NSData *data) {
        
        NSDictionary *sourceDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        
        self.host = [[Host alloc]initWithDictionary:sourceDic];
        //背景图片
        [_imageView setImageWithURL:[NSURL URLWithString:[self.host.backgroundLogo stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
        //博主头像
        [_hostImageView setImageWithURL:[NSURL URLWithString:[self.host.mobileSmallLogo stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
        //博主名字
        _HostNameLable.text = self.host.nickname;
        //博主备注
       // _HostRemarkLable.text = self.host.personalSignature;
        
        _titleLightView.text = [_host.favorites description];
        _titleLable.text = [_host.followings description];
        
           }];
}

//解析发布专辑的数据
- (void)handleAlbumsData
{
    
    NSString *str = [NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/others/ca/album/%@/1/2?device=iPhone", self.introduction.uid];
    [NetHandler getDataWithURL:str completion:^(NSData *data) {
        
        NSDictionary *sourceDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        self.albumTotalCount = [sourceDic objectForKey:@"totalCount"];
        
        NSMutableArray *hostArr = [sourceDic objectForKey:@"list"];
        for (NSDictionary *dic in hostArr) {
            AlbumOfList *albumOfList = [[AlbumOfList alloc]initWithDictionary:dic];
            [self.albumArr addObject:albumOfList];
            [albumOfList release];
        }
        
        if ([self.albumTotalCount intValue] > 2) {
            AlbumOfList *albumOfList = [[AlbumOfList alloc]init];
            
            [self.albumArr addObject:albumOfList];
        }
       
        [self.tableV reloadData];
            }];
}
//解析发布的声音的数据
- (void)handleSoundsData
{
    
    
    NSString *pageId = [NSString stringWithFormat:@"%ld", self.pageId];
    
    NSString *str = [NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/others/ca/track/%@/%@/30?device=iPhone", self.introduction.uid , pageId];
    [NetHandler getDataWithURL:str completion:^(NSData *data) {
        
        NSDictionary *sourceDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];

        NSArray * arr = [sourceDic objectForKey:@"list"];
        
        self.pageId = [[sourceDic objectForKey:@"pageId"] integerValue];
        self.maxPageId = [[sourceDic objectForKey:@"maxPageId"] integerValue];
        self.soundTotalCount = [sourceDic objectForKey:@"totalCount"];
        for (NSDictionary *dic in arr) {
            AlbumDatailsOfList *albumDetailsList = [[AlbumDatailsOfList alloc] initWithDictionary:dic];
            
            [self.soundArr addObject:albumDetailsList];
            
            [albumDetailsList release];
        }
        [self.tableV reloadData];
    }];
    
}



- (void)setupRefresh
{
    //    NSLog(@"进入了setupRefresh");
    // 1.下拉刷新(进入刷新状态就会调用self的headerRereshing)
    
    //    [self.detailsTableView addHeaderWithTarget:self action:@selector(headerRereshing)];
    //    //进入刷新状态(一进入程序就下拉刷新)
    //    [self.detailsTableView headerBeginRefreshing];
    
    
    // 2.上拉加载更多(进入刷新状态就会调用self的footerRereshing)
    [self.tableV addFooterWithTarget:self action:@selector(footerRereshing)];
}



#pragma mark 开始进入刷新状态
- (void)headerRereshing
{
    
    //1. 在这调用请求网络数据方法（刷新数据）
    
    //2. 2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 刷新表格
        [self.tableV reloadData];
        
        // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
        [self.tableV headerEndRefreshing];
    });
}

#pragma mark 进入加载状态
- (void)footerRereshing
{
    //1. 拼接口等操作
    // 请求加载数据
    
    // 如果是音频列表
   
        // 小于最大页码
        if (self.pageId < self.maxPageId) {
            // 页码加1
            ++self.pageId;
            
            
            
            NSString *pageId = [NSString stringWithFormat:@"%ld", self.pageId];
            
            NSString *str = [NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/others/ca/track/%@/%@/30?device=iPhone", self.introduction.uid , pageId];
            [NetHandler getDataWithURL:str completion:^(NSData *data) {
                
                NSDictionary *sourceDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                
                NSArray * arr = [sourceDic objectForKey:@"list"];
                
                self.pageId = [[sourceDic objectForKey:@"pageId"] integerValue];
                self.maxPageId = [[sourceDic objectForKey:@"maxPageId"] integerValue];
                self.soundTotalCount = [sourceDic objectForKey:@"totalCount"];
                for (NSDictionary *dic in arr) {
                    AlbumDatailsOfList *albumDetailsList = [[AlbumDatailsOfList alloc] initWithDictionary:dic];
                    
                    [self.soundArr addObject:albumDetailsList];
                    
                    [albumDetailsList release];
                }
                [self.tableV reloadData];
            }];

            
            
            
        }
        

    
    // 2.2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 刷新表格
        
        // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
        [self.tableV reloadData];
        [self.tableV footerEndRefreshing];
    });
}


#pragma mark 设置section的高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        // 如果section的下标为0 高为0
        return 0;
    } else if (indexPath.section == 1) {
        // 如果下标为1
        if ([self.albumTotalCount intValue] > 2) {
            // 如果总数大于2
            if (indexPath.row == self.albumArr.count - 1) {
                // 高为40
                return 40;
            }
        }
        // 高为80
        return 80;
        
    }
    
    return 100;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 调用数据处理
    [self handleData];
    
    [self handleAlbumsData];
    [self handleSoundsData];
    
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    
    //创建一个imageView
    self.imageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.origin.x, IMAGEVIEW_ORIGIN_Y, self.view.frame.size.width, IMAGEVIEW_ORIGIN_HEITH)];
    self.imageView.alpha = 0.1;
   
    //self.imageView.image = [UIImage imageNamed:@""];
    [self.view addSubview:_imageView];
    [_imageView release];
    
    //创建tableView
    self.tableV = [[UITableView alloc]initWithFrame:CGRectMake(self.view.frame.origin.x, FINAL_HIGHT, self.view.frame.size.width, self.view.frame.size.height - FINAL_HIGHT) style:UITableViewStylePlain];
    // tableView的颜色为透明色
    self.tableV.backgroundColor = [UIColor clearColor];
    // 设置代理人
    self.tableV.delegate = self;
    self.tableV.dataSource = self;
    
    [self.view addSubview:self.tableV];
    
    [self.tableV registerClass:[AlbumOfListCell class] forCellReuseIdentifier:@"AlbumofList"];
    [self.tableV registerClass:[UITableViewCell class] forCellReuseIdentifier:@"aaaa"];
    //[self.tableV registerClass:[AlbumDetailsCell class] forCellReuseIdentifier:@"AlbumDetails"];
    //用一个透明的view作为tabl的headerview
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, DETAIL_HIGHT - FINAL_HIGHT)];
    //把它设为no不会渲染它。效率略高点，
    view.opaque = NO;
    // 将view添加到
    self.tableV.tableHeaderView = view;
    
    CGFloat width = self.tableV.frame.size.width;
    CGFloat height = self.tableV.sectionHeaderHeight;
    
    // 名字
    self.titleLable = [[UILabel alloc]initWithFrame:CGRectMake(0 , 10, width/4, 30)];
    self.titleLable.center = CGPointMake(width / 4, self.titleLable.frame.size.height / 2 + 5);
    self.titleLable.textColor = [UIColor grayColor];
    self.titleLable.textAlignment = NSTextAlignmentCenter;
    
    self.titleLightView = [[UILabel alloc]initWithFrame:CGRectMake(0 , 10, width/4, 30)];
    self.titleLightView.textColor = [UIColor grayColor];
    self.titleLightView.center = CGPointMake(width / 4 * 3, self.titleLightView.frame.size.height / 2 + 5);
    self.titleLightView.textAlignment = NSTextAlignmentCenter;
    
    // 关注按钮
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.frame = CGRectMake(width/6 , height/6*4 + 30, self.tableV.frame.size.width/4, 30);
    self.button.backgroundColor = [UIColor clearColor];
    [self.button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.button setTitle:@"关注" forState:UIControlStateNormal];
    [self.button addTarget:self action:@selector(hostFollowed:) forControlEvents:UIControlEventTouchUpInside];
    self.button.center = CGPointMake(width / 4,  self.titleLable.frame.origin.y + self.titleLable.frame.size.height + 5);
    
    // 点赞按钮
    self.buttonZan = [UIButton buttonWithType:UIButtonTypeCustom];
    self.buttonZan.frame = CGRectMake(self.tableV.frame.size.width/6*4 , self.tableV.sectionHeaderHeight/3*2, self.tableV.frame.size.width/4, 30);
    self.buttonZan.backgroundColor = [UIColor clearColor];
    [self.buttonZan setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.buttonZan setTitle:@"赞过的" forState:UIControlStateNormal];
        self.buttonZan.center = CGPointMake(width / 4 * 3,  self.titleLable.frame.origin.y + self.buttonZan.frame.size.height + 5);
    [self.buttonZan addTarget:self action:@selector(likeButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
//    [self.button addTarget:self action:@selector(changeZan:) forControlEvents:UIControlStateNormal];
    
    
    
    
    
    self.hostImageView = [[UIImageView alloc]initWithFrame:CGRectMake(150, 20, 90, 90)];
       [view addSubview:self.hostImageView];
    self.hostImageView.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imageViewTap:)];
    
    [self.hostImageView addGestureRecognizer:tap];
    
    self.hostImageView.center = CGPointMake(self.view.frame.size.width / 2, self.hostImageView.frame.size.height / 2 + 20);
    self.hostImageView.layer.cornerRadius = self.hostImageView.frame.size.height / 2;
    self.hostImageView.layer.masksToBounds = YES;

    [_hostImageView release];
    
    // 播主名字
    self.HostNameLable = [[UILabel alloc] initWithFrame:CGRectMake(120, 120, 150, 25)];
    self.HostNameLable.center = CGPointMake(self.view.frame.size.width / 2, self.HostNameLable.frame.size.height / 2 + 120);
    self.HostNameLable.textAlignment = 1;
    self.HostNameLable.font = [UIFont fontWithName:@"KaiTi_GB2312" size:18];
    [view addSubview:self.HostNameLable];
    [_HostNameLable release];
    
    self.HostRemarkLable = [[UILabel alloc] initWithFrame:CGRectMake(110, 130, 150, 15)];
    [view addSubview:self.HostRemarkLable];
    [_HostRemarkLable release];
    
    
    [self setupRefresh];
    
    
}

- (void)imageViewTap:(UITapGestureRecognizer *)tap
{
    DeatilsViewController *hostDetailVC = [[DeatilsViewController alloc] init];
    hostDetailVC.introduction = self.introduction;
    [self presentViewController:hostDetailVC animated:YES completion:^{
        
        
    }];
    [hostDetailVC release];
}


#pragma mark 点赞按钮
- (void)likeButtonClicked:(UIButton *)button
{
    
    HostLikeViewController *hostLikeVC = [[HostLikeViewController alloc] init];
    hostLikeVC.introduction = self.introduction;
    [self.navigationController pushViewController:hostLikeVC animated:YES];
    [hostLikeVC release];
    
}
#pragma mark 播主关注
- (void)hostFollowed:(UIButton *)button
{
    HostAttentionViewController *hostAttentionVC = [[HostAttentionViewController alloc] init];
    hostAttentionVC.introduction = self.introduction;
    [self.navigationController pushViewController:hostAttentionVC animated:YES];
    [hostAttentionVC release];
    
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat content = scrollView.contentOffset.y;
    CGRect newFrame = self.imageView.frame;
    //判断当前偏移量状态
    if (content < 0) {
        newFrame.origin.y = IMAGEVIEW_ORIGIN_Y - content / 5;
        self.imageView.frame = newFrame;
    }else if (content >= 0 && content < DETAIL_HIGHT){
        newFrame.origin.y = IMAGEVIEW_ORIGIN_Y - content;
        self.imageView.frame = newFrame;
    }
    
}

#pragma mark section的标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        // section为1的
        return [NSString stringWithFormat:@"发布的专辑  ( %@ )", self.albumTotalCount];
    } else if (section == 2) {
        
        return [NSString stringWithFormat:@"发布的声音  ( %@ )", self.soundTotalCount];
        
    }
    return [NSString stringWithFormat:@"section:%ld", section];
}

// section的个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

#pragma mark section的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 0;
    } else if (section == 1) {
        return self.albumArr.count;
    } else if (section == 2) {
        
        return self.soundArr.count;
        
    }
    return 0;
}

#pragma mark cell的设置
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        // 当section的下标为0
        // 用系统的cell设置
        static NSString *indentifier = @"cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifier];
        if (nil == cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifier];
        }
        cell.textLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row];
        
        return cell;

    } else if (indexPath.section == 1) {
        // 调用专辑的自定义cell
        if ([self.albumTotalCount intValue] > 2) {
            if (indexPath.row == self.albumArr.count - 1) {
                
                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"aaaa"];
                cell.textLabel.frame = cell.frame;
                cell.textLabel.text = @"查看全部专辑";
                cell.textLabel.textAlignment = NSTextAlignmentCenter;
                return cell;
            }
        }
        

        
        AlbumOfListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AlbumofList"];
        
        cell.albumList = [self.albumArr objectAtIndex:indexPath.row];
        return cell;
        
    } else {
        // 调用专辑详情的cell
        static NSString *str = @"datails";
        
        AlbumDetailsCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
        
        if (cell == nil || self.cellTag != 10000 + indexPath.row) {
            
            cell = [[[AlbumDetailsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str] autorelease];
            [cell.audioButton addTarget:self action:@selector(playOfAudio:) forControlEvents:UIControlEventTouchUpInside];
        }
        cell.audioButton.tag = indexPath.row + 10000;
        
        if (self.cellTag == 10000 + indexPath.row) {
            [cell.audioButton removeFromSuperview];
            [cell.contentView addSubview:self.audioBtn];
        }
        AlbumDatailsOfList *datailList = [self.soundArr objectAtIndex:indexPath.row];
        
        NSLog(@"%ld",cell.audioButton.tag);
        
        
        cell.albumDatailsOfList = datailList;
        
        return cell;

        
//        AlbumDetailsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AlbumDetails"];
//        cell.albumDatailsOfList = [self.soundArr objectAtIndex:indexPath.row];
//        
//        return cell;
    }
    
    
    return  nil;
}

#pragma mark 设置section header的高
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        return 40;
    } else if (section == 2) {
        
         return 40;
        
    }
     return 60;
}

// header的view的设置
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
        if (sectionTitle == nil) {
            return nil;
        }
        // Create header view and add label as a subview
        UIView *sectionView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, tableView.bounds.size.height)] autorelease];
        [sectionView setBackgroundColor:[UIColor whiteColor]];
        
        
        UIView *sectionHostView = [[[UIView alloc]initWithFrame:CGRectMake(0, tableView.bounds.size.height, tableView.bounds.size.width, tableView.bounds.size.height)]autorelease];
        [sectionHostView setBackgroundColor:[UIColor clearColor]];
        
        
        [sectionView addSubview:self.titleLable];
        [sectionView addSubview:self.titleLightView];
        [sectionView addSubview:self.button];
        [sectionView addSubview:self.buttonZan];
        return sectionView;

    }
    return nil;
}

#pragma mark 点击cell
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (indexPath.section == 1) {
        if ([self.albumTotalCount intValue] > 2) {
            
            if (indexPath.row == self.albumArr.count - 1) {
                
                AllAlbumOfHostViewController *allAlbumOfHostVC = [[AllAlbumOfHostViewController alloc] init];
                allAlbumOfHostVC.introduction = self.introduction;
                [self.navigationController pushViewController:allAlbumOfHostVC animated:YES];
                
                [allAlbumOfHostVC release];
                
            }else { 
                AlbumDetailsViewController *albumDetailsVC = [[AlbumDetailsViewController alloc] init];
                
                albumDetailsVC.albumOfList = [self.albumArr objectAtIndex:indexPath.row];
                [self.navigationController pushViewController:albumDetailsVC animated:YES];
                [albumDetailsVC release];
                
            }

            
        }else {
            
          
            
            
            
            
            AlbumDetailsViewController *albumDetailsVC = [[AlbumDetailsViewController alloc] init];
            
            albumDetailsVC.albumOfList = [self.albumArr objectAtIndex:indexPath.row];
            [self.navigationController pushViewController:albumDetailsVC animated:YES];
            [albumDetailsVC release];
 
        }

    } else if (indexPath.section == 2) {
        
        
        self.cell = (AlbumDetailsCell *)[tableView cellForRowAtIndexPath:indexPath];
        
        AlbumDatailsOfList *dataList = [self.soundArr objectAtIndex:indexPath.row];
        
        _mainPlayVC = [MainPlayerViewController defaultPlayer];
        
        
        _mainPlayVC.albumDatail = dataList;
        _mainPlayVC.trackId = dataList.trackId;
        [_mainPlayVC.listArr removeAllObjects];
        [_mainPlayVC.listArr addObjectsFromArray:self.arr];
        _mainPlayVC.index = indexPath.row;
        _mainPlayVC.navi = self.navigationController;
        
        _audioPlayer = [AudioPlayer shareInstance];
        
        if (![_audioPlayer.button isEqual:_cell.audioButton]) {
            
            [_audioPlayer stop];
            self.audioBtn = _cell.audioButton;
            
            ;
            _audioPlayer.button = _cell.audioButton;
            self.cellTag = _cell.audioButton.tag;
            _audioPlayer.url = [NSURL URLWithString:dataList.playUrl64];
            [_audioPlayer play];
            
        }
        
        
        // _mainPlayVC.audioButton = _cell.audioButton;
        
        [_mainPlayVC showDetailInformation];
//        [self presentViewController:_mainPlayVC animated:YES completion:^{
//            
//            
//        }];
        
        CATransition *transition = [CATransition animation];
        transition.duration = 0.3f;
        transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        transition.type = @"push";
        transition.subtype = kCATransitionFromTop;
        transition.delegate = self;
        [self.navigationController.view.layer addAnimation:transition forKey:nil];
        
        [self.navigationController pushViewController:_mainPlayVC animated:NO];
        
        
       // [self.navigationController pushViewController:_mainPlayVC animated:YES];
    }
    
    
}


#pragma mark 点击播放的按钮

- (void)playOfAudio:(AudioButton *)button
{
    
    self.audioBtn = button;
    self.cellTag = button.tag;
    _audioPlayer =  [AudioPlayer shareInstance];
    _audioPlayer.imagePath = [[self.soundArr objectAtIndex:button.tag - 10000] coverLarge];
    if ([_audioPlayer.button isEqual: button]) {
        
        [_audioPlayer play];
        
    } else {
        
        _mainPlayVC = [MainPlayerViewController defaultPlayer];
        [_mainPlayVC.listArr removeAllObjects];
        [_mainPlayVC.listArr addObjectsFromArray:self.soundArr];
        _mainPlayVC.index = button.tag - 10000;
        _mainPlayVC.trackId = [[self.soundArr objectAtIndex:button.tag - 10000] trackId];
        [_mainPlayVC showDetailInformation];
        [_audioPlayer stop];
        
        _audioPlayer.button = button;

        _audioPlayer.url = [NSURL URLWithString:[[self.soundArr objectAtIndex:button.tag - 10000] playUrl64]];
        
        [_audioPlayer play];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
